package com.xiaojianhx.demo.base;

public class TestEqualsAndHashCode {

    public static void main(String[] args) {

        var f = new Father("a");
        var s = new Son("a");

        System.out.println(f.equals(s));
        System.out.println(s.equals(f));
    }
}

class Father {

    private String name;

    public Father(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int hashCode() {
        return 0;
    }

    public boolean equals(Object obj) {

        if (obj == null) {
            return false;
        }

        if (obj instanceof Father f) {
            return f.name.equals(name);
        }

        return false;
    }
}

class Son extends Father {

    public Son(String name) {
        super(name);
    }
}